package com.shuke.my_test.explain.service;


import com.shuke.my_test.explain.domain.User;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 舒克、舒克
 * @date 2025/7/10 10:01
 * @description
 */
@Service
public class ExplainUser {

    private static final String fields = "序号\t姓名\t年龄\n" +
            "\n" +
            "1\t小王\t10\n" +
            "\n" +
            "2\t小红\t20\n" +
            "\n" +
            "3\t小兰\t30";


    public List<User> explainUser(){
        List<User> users = new ArrayList<>();

        String [] rows = fields.split("\n");

        for (int i = 1; i < rows.length; i++){
            String row = rows[i].trim();
            if (row.isEmpty()) continue;
            String [] fields = rows[i].split("\t");

            User user = new User(Integer.parseInt(fields[0]), fields[1], Integer.parseInt(fields[2]));
            users.add(user);
        }

        return users;
    }
}
